package com.ctrip.ec.api.admin.controller.dict;
import com.ctrip.ec.api.admin.model.query.QueryModel;
import com.ctrip.ec.biz.entity.dict.CategoryEntity;
import com.ctrip.ec.biz.entity.dict.DictCategory;
import com.ctrip.ec.dal.PagerSetting;
import com.ctrip.ec.api.admin.common.RequestContext;
import com.ctrip.ec.biz.dao.dict.DictDao;
import com.ctrip.ec.biz.entity.dict.DictEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("dict")
public class DictController{
    @Autowired
    private DictDao dict;

    @GetMapping("list")
    public List<DictEntity> list(@RequestParam String category) throws  SQLException{
        List<DictEntity> list = dict.list( DictCategory.valueOf(category));
        return list;
    }

    @GetMapping("category/list")
    public List<CategoryEntity> categorys(){
        List<CategoryEntity> list = new ArrayList<>();
        for(DictCategory category : DictCategory.values()){
            CategoryEntity entity = new CategoryEntity();
            entity.setCode(category.getCode());
            entity.setName(category.getName());
            list.add(entity);
        }
        return list;
    }

    @GetMapping("detail/{id}")
    public  DictEntity detail(@PathVariable Long id) throws SQLException {
        return dict.entity(id);
    }

    @PostMapping("save")
    public  Long save(@RequestBody DictEntity entity) throws SQLException {
        dict.save(entity);
        return entity.getId();
    }

    @PostMapping("delete")
    public  void delete(@RequestBody List<Long> ids) throws SQLException {
        dict.delete(ids);
    }
    @PostMapping("erase")
    public void erase(@RequestBody List<Long> ids) throws  SQLException{
        dict.erase(ids);
    }

    @PostMapping("unerase")
    public  void unerase(@RequestBody List<Long> ids) throws  SQLException{
        dict.unerase(ids);
    }
}
